package com.xiaoyu.izf.model;

import cn.hutool.core.date.DateUtil;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.util.StringUtils;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

@Entity
@Table(name = "user_info", schema = "izf", catalog = "")
//@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
public class UserInfo {
    private int id;
    private String userName;
    private String pwd;
    private Integer vipType; //0：非vip 1:省  2：市 3：区
    private String nickName;
    private String headImgUrl;
    private Timestamp regTime;
    private Timestamp lastLoginTime;
    private String token;
    private String pushCode;
    private Integer pushUid;      //1级推广
    private Integer gradePushUid; //二级推广
    private Integer commission;
    private Double commissionSerial;//流水佣金
    private Integer commissionDeposit;
    private Integer commissionPaid;
    private Integer commissionPaying;
    private Integer isDel;
    private Integer isAdmin;
    private String officialServiceNumber;
    private Integer isTest;
    private Integer toTheAccount;
    private String regionCode;
    private Integer source;

    private String officialServiceNumberView;
    private String regTimeStr;
    private VipInfo vipInfo;
    private String vipTypeName;

//    @FieldSet(beanClass = VipInfoDao.class,method = "findone",param = "vipType",source = "vipName")
//    @Transient
//    private String vipName;
//    public String getVipName() {
//        return vipName;
//    }
//    public void setVipName(String vipName) {
//        this.vipName = vipName;
//    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "user_name")
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Basic
    @Column(name = "pwd")
    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    @Basic
    @Column(name = "vip_type")
    public Integer getVipType() {
        return vipType;
    }

    public void setVipType(Integer vipType) {
        this.vipType = vipType;
    }

    @Basic
    @Column(name = "nick_name")
    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    @Basic
    @Column(name = "head_img_url")
    public String getHeadImgUrl() {
        return headImgUrl;
    }

    public void setHeadImgUrl(String headImgUrl) {
        this.headImgUrl = headImgUrl;
    }

    @Basic
    @Column(name = "reg_time")
    public Timestamp getRegTime() {
        return regTime;
    }

    public void setRegTime(Timestamp regTime) {
        this.regTime = regTime;
    }

    @Basic
    @Column(name = "last_login_time")
    public Timestamp getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(Timestamp lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    @Basic
    @Column(name = "token")
    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    @Basic
    @Column(name = "push_code")
    public String getPushCode() {
        return pushCode;
    }

    public void setPushCode(String pushCode) {
        this.pushCode = pushCode;
    }

    @Basic
    @Column(name = "push_uid")
    public Integer getPushUid() {
        return pushUid;
    }

    public void setPushUid(Integer pushUid) {
        this.pushUid = pushUid;
    }

    @Basic
    @Column(name = "grade_push_uid")
    public Integer getGradePushUid() {
        return gradePushUid;
    }

    public void setGradePushUid(Integer gradePushUid) {
        this.gradePushUid = gradePushUid;
    }

    @Basic
    @Column(name = "commission")
    public Integer getCommission() {
        return commission;
    }

    public void setCommission(Integer commission) {
        this.commission = commission;
    }

    @Basic
    @Column(name = "commission_serial")
    public Double getCommissionSerial() {
        return commissionSerial;
    }

    public void setCommissionSerial(Double commissionSerial) {
        this.commissionSerial = commissionSerial;
    }

    @Basic
    @Column(name = "commission_deposit")
    public Integer getCommissionDeposit() {
        return commissionDeposit;
    }

    public void setCommissionDeposit(Integer commissionDeposit) {
        this.commissionDeposit = commissionDeposit;
    }

    @Basic
    @Column(name = "commission_paid")
    public Integer getCommissionPaid() {
        return commissionPaid;
    }

    public void setCommissionPaid(Integer commissionPaid) {
        this.commissionPaid = commissionPaid;
    }

    @Basic
    @Column(name = "commission_paying")
    public Integer getCommissionPaying() {
        return commissionPaying;
    }

    public void setCommissionPaying(Integer commissionPaying) {
        this.commissionPaying = commissionPaying;
    }

    @Basic
    @Column(name = "is_del")
    public Integer getIsDel() {
        return isDel;
    }

    public void setIsDel(Integer isDel) {
        this.isDel = isDel;
    }

    @Basic
    @Column(name = "is_admin")
    public Integer getIsAdmin() {
        return isAdmin;
    }

    public void setIsAdmin(Integer isAdmin) {
        this.isAdmin = isAdmin;
    }

    @Basic
    @Column(name = "official_service_number")
    public String getOfficialServiceNumber() {
        return officialServiceNumber;
    }

    public void setOfficialServiceNumber(String officialServiceNumber) {
        this.officialServiceNumber = officialServiceNumber;
    }

    @Basic
    @Column(name = "to_the_account")
    public Integer getToTheAccount() {
        return toTheAccount;
    }

    public void setToTheAccount(Integer toTheAccount) {
        this.toTheAccount = toTheAccount;
    }

    @Transient
    public String getRegTimeStr() {
        return DateUtil.formatDateTime(regTime);
    }

    public void setRegTimeStr(String regTimeStr) {
        this.regTimeStr = regTimeStr;
    }

    @Basic
    @Column(name = "is_test")
    public Integer getIsTest() {
        return isTest;
    }

    public void setIsTest(Integer isTest) {
        this.isTest = isTest;
    }

    @Basic
    @Column(name = "region_code")
    public String getRegionCode() {
        return regionCode;
    }

    public void setRegionCode(String regionCode) {
        this.regionCode = regionCode;
    }

    @Basic
    @Column(name = "source")
    public Integer getSource() {
        return source;
    }

    public void setSource(Integer source) {
        this.source = source;
    }

    @Transient
    public String getOfficialServiceNumberView() {
        if (!StringUtils.isEmpty(officialServiceNumber) && "C".equals(officialServiceNumber.substring(0, 1))) {
            return officialServiceNumber;
        }
        if (this.vipType == 1) {
            return "CAZFH" + officialServiceNumber;
        } else if (this.vipType == 2) {
            return "CAZFH" + officialServiceNumber;
        } else if (this.vipType == 3) {
            return "CAZFH" + officialServiceNumber;
        } else if (this.vipType == 21) {
            return "CAZFS" + officialServiceNumber;
        } else if (this.vipType == 23) {
            return "CAZFQ" + officialServiceNumber;
        }
        return "粉丝";
    }

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, optional = true)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "vip_type", referencedColumnName = "id", insertable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
    public VipInfo getVipInfo() {
        return vipInfo;
    }

    public void setVipInfo(VipInfo vipInfo) {
        this.vipInfo = vipInfo;
    }

    @Transient
    public String getVipTypeName() {
        if (this.vipType == 1) {
            return "运营商";
        } else if (this.vipType == 2) {
            return "渠道商";
        } else if (this.vipType == 3) {
            return "推广员";
        } else if (this.vipType == 21) {
            return "省级服务商";
        } else if (this.vipType == 23) {
            return "区县服务商";
        }
        return "粉丝";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UserInfo userInfo = (UserInfo) o;
        return id == userInfo.id &&
                Objects.equals(userName, userInfo.userName) &&
                Objects.equals(pwd, userInfo.pwd) &&
                Objects.equals(vipType, userInfo.vipType) &&
                Objects.equals(nickName, userInfo.nickName) &&
                Objects.equals(headImgUrl, userInfo.headImgUrl) &&
                Objects.equals(regTime, userInfo.regTime) &&
                Objects.equals(lastLoginTime, userInfo.lastLoginTime) &&
                Objects.equals(token, userInfo.token) &&
                Objects.equals(pushCode, userInfo.pushCode) &&
                Objects.equals(pushUid, userInfo.pushUid) &&
                Objects.equals(gradePushUid, userInfo.gradePushUid) &&
                Objects.equals(commission, userInfo.commission) &&
                Objects.equals(commissionDeposit, userInfo.commissionDeposit) &&
                Objects.equals(commissionPaid, userInfo.commissionPaid) &&
                Objects.equals(commissionPaying, userInfo.commissionPaying) &&
                Objects.equals(isDel, userInfo.isDel);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, userName, pwd, vipType, nickName, headImgUrl, regTime, lastLoginTime, token, pushCode, pushUid, gradePushUid, commission, commissionDeposit, commissionPaid, commissionPaying, isDel);
    }

    @Override
    public String toString() {
        return "UserInfo{" +
                "id=" + id +
                ", userName='" + userName + '\'' +
                ", pwd='" + pwd + '\'' +
                ", vipType=" + vipType +
                ", nickName='" + nickName + '\'' +
                ", headImgUrl='" + headImgUrl + '\'' +
                ", regTime=" + regTime +
                ", lastLoginTime=" + lastLoginTime +
                ", token='" + token + '\'' +
                ", pushCode='" + pushCode + '\'' +
                ", pushUid=" + pushUid +
                ", gradePushUid=" + gradePushUid +
                ", commission=" + commission +
                ", commissionDeposit=" + commissionDeposit +
                ", commissionPaid=" + commissionPaid +
                ", commissionPaying=" + commissionPaying +
                ", isDel=" + isDel +
                ", isAdmin=" + isAdmin +
                ", officialServiceNumber='" + officialServiceNumber + '\'' +
                ", isTest=" + isTest +
                ", toTheAccount=" + toTheAccount +
                ", regionCode='" + regionCode + '\'' +
                ", officialServiceNumberView='" + officialServiceNumberView + '\'' +
                ", regTimeStr='" + regTimeStr + '\'' +
                ", vipInfo=" + vipInfo +
                ", vipTypeName='" + vipTypeName + '\'' +
                '}';
    }
}
